package com.yd.sdk.analysisappsflyer;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

import com.appsflyer.AppsFlyerConversionListener;
import com.appsflyer.AppsFlyerLib;
import com.yd.sdk.analysis.AnalysisAbstractClass;

import java.util.Map;

public class AnalysisAppsFlyerImp extends AnalysisAbstractClass {


    @Override
    public void onCreate(Activity activity, Bundle savedInstanceState) {
        id = "AppsFlyer";
        this.activity = activity;
    }

    @Override
    public void onPause() {

    }

    @Override
    public void onResume() {

    }

    @Override
    public void onDestroy() {

    }

    @Override
    public void Initialize(String key) {
        this.id = id;
        AppsFlyerConversionListener conversionListener = new AppsFlyerConversionListener() {
            @Override
            public void onConversionDataSuccess(Map<String, Object> conversionData) {

                for (String attrName : conversionData.keySet()) {
                    Log.d("LOG_TAG", "attribute: " + attrName + " = " + conversionData.get(attrName));
                }
            }

            @Override
            public void onConversionDataFail(String errorMessage) {
                Log.d("LOG_TAG", "error getting conversion data: " + errorMessage);
            }

            @Override
            public void onAppOpenAttribution(Map<String, String> attributionData) {
                for (String attrName : attributionData.keySet()) {
                    Log.d("LOG_TAG", "attribute: " + attrName + " = " + attributionData.get(attrName));
                }
            }

            @Override
            public void onAttributionFailure(String errorMessage) {
                Log.d("LOG_TAG", "error onAttributionFailure : " + errorMessage);
            }
        };

        //初始化
        AppsFlyerLib.getInstance().init(key, conversionListener, activity);

        //开始
        AppsFlyerLib.getInstance().start(activity);
    }

    @Override
    public void LogEvent(String name, String key, String message) {

    }
}
